package order

import (
	"fmt"
	"net/http"
	"strconv"

	"oil-station-backend/internal/logic/order"
	"oil-station-backend/internal/svc"

	"github.com/gorilla/mux"
	"github.com/zeromicro/go-zero/rest/httpx"
)

func GetOrderDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		vars := mux.Vars(r)
		idStr, ok := vars["id"]
		if !ok {
			httpx.Error(w, fmt.Errorf("缺少订单ID"))
			return
		}

		id, err := strconv.ParseInt(idStr, 10, 64)
		if err != nil {
			httpx.Error(w, fmt.Errorf("无效的订单ID"))
			return
		}

		l := order.NewGetOrderDetailLogic(r.Context(), svcCtx)
		resp, err := l.GetOrderDetail(id)
		if err != nil {
			httpx.Error(w, err)
		} else {
			httpx.OkJson(w, resp)
		}
	}
}